package com.hhkj.study.admin.resource.service.extend.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.hhkj.study.admin.course.enums.CourseAssocResourceTypeEnum;
import com.hhkj.study.admin.resource.entity.ResourceCourseBase;
import com.hhkj.study.admin.resource.entity.ResourceCourseDoc;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseDocDo;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseDocPo;
import com.hhkj.study.admin.resource.service.base.ResourceCourseDocService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseBaseExtendService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseDocExtendService;
import com.ruoyi.common.base.biz.service.extend.BaseExtendServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ResourceCourseDocExtendServiceImpl extends BaseExtendServiceImpl<ResourceCourseDoc, ResourceCourseDocDo, ResourceCourseDocPo, ResourceCourseDocService> implements ResourceCourseDocExtendService, ResourceCourseBaseExtendService {
    @Override
    public ResourceCourseDoc getByNameCourseType(String name, Long courseType) {
        LambdaQueryWrapper<ResourceCourseDoc> docQuery = new LambdaQueryWrapper<>();
        docQuery.eq(ResourceCourseDoc::getName, name).eq(ObjectUtil.isNotNull(courseType), ResourceCourseDoc::getCourseType, courseType).last("LIMIT 1");
        return this.getService().getOne(docQuery);
    }

    @Override
    public CourseAssocResourceTypeEnum getCourseResourceTypeEnum() {
        return CourseAssocResourceTypeEnum.DOC;
    }

    @Override
    public List<ResourceCourseDocPo> listByIdList(Collection<Long> idList) {
        if (CollectionUtil.isEmpty(idList)) {
            return Lists.newArrayList();
        }
        ResourceCourseDocDo resourceCourseDocDo = new ResourceCourseDocDo();
        resourceCourseDocDo.setIdList(Lists.newArrayList(idList));
        return this.getService().listPoByDo(resourceCourseDocDo);
    }

    @Override
    public List<? extends ResourceCourseBase> getResouceListByIdList(Collection<? extends Serializable> idList, List<? extends ResourceCourseBase> resourceList) {
        if (CollectionUtil.isEmpty(idList) || CollectionUtil.isEmpty(resourceList)) {
            return Lists.newArrayList();
        }
        List<ResourceCourseDoc> resourceCourseList = BeanUtil.copyToList(resourceList, ResourceCourseDoc.class);
        return resourceCourseList.stream().filter(e -> idList.contains(e.getId())).collect(Collectors.toList());
    }
}
